package com.yy.market.mvp.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yy.market.mvp.presenter.BasePresenter;

import butterknife.ButterKnife;


/**
 * Created by luweibin on 2016/6/30.
 */
public abstract class BaseFragment<T extends BasePresenter> extends Fragment {
    T presenter;
    private View rootView;
    protected Context context;
    protected LayoutInflater mInflater;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this.getActivity();
        initPresenter();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
    Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(getLayoutId(), null);
            ButterKnife.bind(this,rootView);
            mInflater = LayoutInflater.from(context);
            initView(inflater,container,rootView);
            loadData();
        }
        ViewGroup parentView = (ViewGroup) rootView.getParent();
        if (parentView != null) {
            parentView.removeView(rootView);
        }
        return rootView;
    }


    protected abstract int getLayoutId();

    protected abstract void initPresenter();

    protected abstract void initView(LayoutInflater inflater,ViewGroup container,View view);

    protected abstract void loadData();


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    /**
     * 显示正在加载动画图
     */
    public void showProgress() {

    }

    /**
     * 隐藏正在加载图
     */
    public void dismissProgress() {

    }
}
